package com.papa91.common;

import java.io.File;

public class FileWrapper implements Comparable {
	/** File */
	public File mfile;

	public FileWrapper(File file) {
		this.mfile = file;
	}

	public int compareTo(Object obj) {
		assert obj instanceof FileWrapper;

		FileWrapper castObj = (FileWrapper) obj;
		File castFile = castObj.getFile();
		if (this.mfile.getName().compareTo(castFile.getName()) > 0) {
			if (mfile.isDirectory() && castFile.isFile())
				return -1;
			else if (mfile.isFile() && castFile.isDirectory())
				return 1;
			return 1;
		} else if (this.mfile.getName().compareTo(castFile.getName()) < 0) {
			if (mfile.isDirectory() && castFile.isFile())
				return -1;
			else if (mfile.isFile() && castFile.isDirectory())
				return 1;
			return -1;
		} else {
			if (mfile.isDirectory() && castFile.isFile())
				return -1;
			else if (mfile.isFile() && castFile.isDirectory())
				return 1;
			return 0;
		}
	}

	public File getFile() {
		return this.mfile;
	}
}
